package com.cskaoyan.controller.admincontroller;

import com.cskaoyan.bean.po.MarketStorage;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.chaosbean.storage.vo.StorageListVO;
import com.cskaoyan.service.adminservice.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author jackX
 * @datetime 2022/12/28 22:45
 * @description: TODO:
 */
@RestController
@RequestMapping("admin/storage")
public class StorageController {
    @Autowired
    StorageService storageService;

    /**
     * 上传管理员头像
     * @param file 二进制文件数据
     * @return
     */
    //http://182.92.235.201:8083/admin/storage/create
    @RequestMapping("create")
    public BaseRespVo uploadPic(MultipartFile file) {
        //上传管理员头像
        MarketStorage marketStorage = storageService.insertCreateFile(file);
        return BaseRespVo.okYa(marketStorage);
    }

    /**
     * 对象存储分页信息
     * @param info 对象存储分页的所需数据
     * @param key 根据对象的key值进行查询
     * @param name 根据对象的name进行查询
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info, String key, String name) {
        StorageListVO storage = storageService.list(info, key, name);
        return BaseRespVo.okYa(storage);
    }

    /**
     * 更新对象存储的相关信息
     * @param storage 所更新的字段以对象的形式进行接受处理
     * @return
     */
    //http://182.92.235.201:8083/admin/storage/update
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketStorage storage) {
        //修改对象的存储信息
        MarketStorage update = storageService.update(storage);
        return BaseRespVo.ok(update);
    }

    /**
     * 删除对象存储的信息
     * @param storage 所删除的字段以对象的形式进行接受处理
     * @return
     */
    //http://182.92.235.201:8083/admin/storage/delete
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketStorage storage) {
        //删除对象存储的信息
        storageService.delete(storage);
        return BaseRespVo.ok();
    }
}
